home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Commun⁄Network / Telnet 2.5.src.ThinkC / source / tekrgmac.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-14  |  11.8 KB  |  638 lines  |  [TEXT/MPS ]

  1. #ifdef lint
  2. static char *SCCSid = "%W%    (NCSA)    %G%";
  3. #endif
  4.  
  5. /*
  6.  
  7. rgmac.c by Gaige B. Paulsen
  8.   spawned from rgp.c by Aaron Contorer for NCSA
  9. Copyright 1987, board of trustees, University of Illinois
  10.  
  11. Routines for Macintosh Window output.  
  12.  
  13. */
  14.  
  15.  
  16. /* 
  17.  *    Include files 
  18.  */
  19.  
  20. #include <stdio.h>
  21. #include <String.h>
  22.  
  23. #include <Controls.h>
  24. #include <Dialogs.h>
  25. #include <Events.h>
  26. #include <OSutils.h>
  27. #include <Packages.h>
  28. #include <Quickdraw.h>
  29. #include <Windows.h>
  30. #include <Memory.h>
  31.  
  32. #ifdef MPW
  33. #include "mpw.h"
  34. #endif MPW
  35. #include "configrec.h"
  36. #include "maclook.h"
  37. #include "whatami.h"
  38. #include "vgtek.h"
  39. #include "tools.h"
  40. #include "util.h"
  41. #include "rsmac.h"
  42.  
  43. #define TRUE 1
  44. #define FALSE 0
  45.  
  46. #define SPLASH_SQUARED    4
  47.  
  48. /*
  49.  * display structure....
  50.  */
  51.  
  52. struct RGMwindows {
  53. GrafPtr
  54.     wind;
  55. int 
  56.     xorigin,
  57.     yorigin,
  58.     xscale,
  59.     yscale,
  60.     vg,
  61.     vs,
  62.     inuse,
  63.     ingin;
  64. unsigned char
  65.     *name;
  66. int 
  67.     width,
  68.     height;
  69. ControlHandle
  70.     zoom,
  71.     vert,
  72.     horiz;
  73.     } *RGMwind[ MAXWIND ];    /* BYU - changed from an array of structure to an array of pointers */
  74.  
  75. long RGMlastclick;
  76.  
  77. int RGMcolor[]=
  78.     { 30,            /* black */
  79.       33,            /* white */
  80.       205,            /* red */
  81.       341,            /* green */
  82.       409,            /* blue */
  83.       273,            /* cyan */
  84.       137,            /* magenta */
  85.       69            /* yellow */
  86.       };
  87.  
  88.  
  89. char *macname = "Macintosh Windows";
  90.  
  91. int RGsetwind
  92.   (
  93.     int dnum
  94.   )
  95. {
  96.  
  97.     if (dnum<0 || dnum>=MAXWIND) return(-1);
  98.  
  99.     if (!RGMwind[dnum]->inuse) return(-1);
  100.  
  101.     SetPort( RGMwind[dnum]->wind);
  102.     return(0);
  103. }
  104.  
  105. RGMgin(w)
  106. {
  107.     if (RGsetwind(w)) return(-1);
  108.  
  109.     setgraphcurs();
  110.     RGMwind[w]->ingin=1;
  111. }
  112.  
  113. RGMoutfunc(f)
  114.     int (*f)();
  115.   {
  116. #pragma unused(f)
  117.   }
  118.  
  119.  
  120. RGMpencolor(w, color)
  121. {
  122.     if (RGsetwind(w) ) return(-1);
  123.  
  124.     ForeColor((long) RGMcolor[color] );
  125. }
  126.  
  127. RGMclrscr(w)
  128. {
  129.     if (RGsetwind(w) ) return(-1);
  130.  
  131.     PaintRect(&RGMwind[w]->wind->portRect);
  132. }
  133.  
  134. RGMclose(w)
  135. {
  136.     if (RGsetwind(w) ) return(-1);
  137.  
  138.     DisposeWindow(RGMwind[w]->wind);
  139.     RGMwind[w]->inuse  = FALSE;
  140.  
  141. }
  142.  
  143. RGMpoint(w,x,y)
  144. {
  145.     if (RGsetwind(w) ) return(-1);
  146.  
  147.     MoveTo(x,y);
  148.     LineTo(x,y);
  149.  
  150. RGMdrawline(w,x0,y0,x1,y1)
  151. int w,x0,y0,x1,y1;
  152. {
  153.     if (RGsetwind(w) ) return(-1);
  154.  
  155.     x0 = (int) ((long) ((long) x0 * (long) RGMwind[w]->width) / (long) INXMAX);                            /* BYU LSC */
  156.     y0 = RGMwind[w]->height - (int) ((long) ((long) y0 * (long) RGMwind[w]->height) / (long) INYMAX);    /* BYU LSC */
  157.     x1 = (int) ((long) ((long) x1 * (long) RGMwind[w]->width) / (long) INXMAX);                            /* BYU LSC */
  158.     y1 = RGMwind[w]->height - (int) ((long) ((long) y1 * (long) RGMwind[w]->height) / (long) INYMAX);    /* BYU LSC */
  159.  
  160.     MoveTo(x0,y0);
  161.     LineTo(x1,y1);
  162. }
  163.  
  164. RGMpagedone(w)
  165.   {
  166. #pragma unused(w)
  167.   }
  168.  
  169. RGMdataline(w,data,count)
  170.   {
  171. #pragma unused(w, data, count)
  172.   }
  173.  
  174.  
  175. RGMcharmode(w,rotation,size)
  176.   {
  177. #pragma unused(w, rotation, size)
  178.   }
  179.  
  180. RGMshowcur()
  181.   {
  182.   }
  183.  
  184. RGMlockcur()
  185.   {
  186.   }
  187.  
  188. RGMhidecur()
  189.   {
  190.   }
  191.  
  192. RGMbell(w)
  193.   {
  194. #pragma unused(w)
  195.   }
  196.  
  197. RGMuncover(w)
  198.   {
  199. #pragma unused(w)
  200.   }
  201.  
  202. char *RGMdevname() {
  203.     return(macname);
  204. }
  205.  
  206. int RGMalloc()            /* BYU - allocate this structure to save global space */
  207. {                    /* BYU */
  208.     int i;                            /* BYU */
  209.     for(i=0; i<MAXWIND; i++) {        /* BYU */
  210.         RGMwind[i] = (struct RGMwindows *) NewPtr((long) sizeof(struct RGMwindows));    /* BYU */
  211.         if (RGMwind[i]) {                        /* BYU */
  212.             RGMwind[i]->wind = (GrafPtr) 0;        /* BYU */
  213.             RGMwind[i]->vg = -1;                /* BYU - necessary */
  214.             RGMwind[i]->vs = -1;                /* BYU */
  215.             RGMwind[i]->inuse = 0;                /* BYU - necessary */
  216.         } else                                     /* BYU */
  217.             return -1;                /* BYU - insufficient memory */
  218.     }                        /* BYU */
  219.     return(0);        /* BYU */
  220. }                    /* BYU */
  221.  
  222. RGMinit()
  223. {
  224.     int i;
  225.     for (i = 0; i < MAXWIND; i++)
  226.         RGMwind[i]->inuse = 0;
  227. }
  228.  
  229. RGMinfo(w,v,a,b,c,d)
  230.     int w,a,b,c,d,v;
  231.   {
  232. #pragma unused(a, b, c, d)
  233.     RGMwind[w]->vg=v;
  234.   }
  235.  
  236. RGMgmode()
  237. {}
  238.  
  239. RGMtmode()
  240. {}
  241.  
  242. RGMnewwin()
  243. {
  244. int i = 0;
  245.  
  246.     while ((i < MAXWIND) && (RGMwind[i]->inuse)) i++;
  247.  
  248.     if (i >= MAXWIND) return(-1);
  249.  
  250.     RGMwind[i]->wind = GetNewWindow(256, (Ptr) 0L, (WindowPtr) -1L);
  251.  
  252.     if (RGMwind[i]->wind == 0L) return(-1);
  253.  
  254.     RGMwind[i]->vg = -1;                /* BYU */
  255.     RGMwind[i]->vs = -1;                /* BYU */
  256.     RGMwind[i]->xorigin = 0;
  257.     RGMwind[i]->yorigin = 0;
  258.     RGMwind[i]->xscale  = WINXMAX;    /* BYU LSC - need the "W" here */
  259.     RGMwind[i]->yscale  = WINYMAX;    /* BYU LSC - need the "W" here */
  260.     RGMwind[i]->width   = 400;        /* BYU LSC - was 256 (size of old window resource */
  261.     RGMwind[i]->height  = 300;        /* BYU LSC - was 342 (size of old window resource */
  262.     RGMwind[i]->inuse   = TRUE;
  263.     RGMwind[i]->ingin   = 0;        /* BYU LSC */
  264.  
  265.     ValidRect(&RGMwind[i]->wind->portRect);
  266.  
  267.     return(i);
  268. }
  269.  
  270. int RGfindbyVG
  271.   (
  272.     int vg
  273.   )
  274. {
  275. int i = 0;
  276.  
  277.     while ((i < MAXWIND) && ((!RGMwind[i]->inuse) || (RGMwind[i]->vg != vg)))
  278.         i++;
  279.     if (i >= MAXWIND) return(-1);
  280.     return(i);
  281. }
  282.  
  283. int RGattach
  284.   (
  285.     int vg,
  286.     int virt,
  287.     char *name
  288.   )
  289. {
  290. int        dnum;
  291. long    time;
  292. char    myname[256],ts[256];
  293.  
  294.     if ((dnum = RGfindbyVG(vg)) < 0) return(-1);
  295.  
  296. #if 0                                                                /* BYU LSC - not needed */
  297. sprintf(ts,"RGattach: vg = %d, vs = %d, \042%s\042);  dnum = %d",    /* BYU */
  298.     vg,virt,name,dnum);                                                /* BYU */
  299. putln(ts);
  300. #endif                                                            /* BYU LSC - not needed */
  301.  
  302.     RGMwind[dnum]->vs = virt;
  303.     RGMwind[dnum]->name = (unsigned char *) NewPtr((long) 256);        /* BYU LSC */
  304.  
  305.     if (RGMwind[dnum]->name == 0L) return(-2);
  306.  
  307. #if 1                                    /* BYU */
  308.     myname[0] = 165;                    /* BYU - the "dot" */
  309.     strncpy(&myname[1],name,254);        /* BYU - don't copy too much */
  310. #else                                    /* BYU */
  311.     RGMwind[dnum]->name[0] = 165;
  312.     strncpy(&RGMwind[dnum]->name[1],name,255);
  313. #endif                                    /* BYU */
  314.  
  315.     GetDateTime((unsigned long *) &time);
  316.     IUTimeString(time,FALSE,(unsigned char *) ts);        /* BYU LSC - Put time in the temp string */
  317.     p2cstr(ts);                                            /* BYU LSC */
  318.  
  319. #if 1                                    /* BYU */
  320.     strncat(myname,"  ",2);                /* BYU - was 4 - Space, please */
  321.     strncat(myname,ts,64);                /* BYU - Place the time string at the end */
  322.     strcpy((char *) RGMwind[dnum]->name,myname);    /* BYU LSC */
  323. #else                                    /* BYU */
  324.     strncat(RGMwind[dnum]->name,"  ",255);            /* Space, please */
  325.     strncat(RGMwind[dnum]->name,ts,255);            /* Place the time string at the end */
  326. #endif
  327.  
  328. #if 1                                            /* BYU */
  329.     if (RGMwind[dnum]->wind != (GrafPtr) 0) {    /* BYU LSC */
  330.         c2pstr(myname);                            /* BYU LSC */
  331.         SetWTitle(RGMwind[dnum]->wind,myname);    /* BYU LSC */
  332.     }
  333. #else                                            /* BYU */
  334.     SetWTitle(RGMwind[dnum]->wind,RGMwind[dnum]->name);
  335. #endif                                            /* BYU */
  336.     return(0);
  337. }
  338.  
  339.  
  340. int RGdetach        /* BYU */
  341.   (
  342.     int vg            /* BYU */
  343.   )
  344. {
  345. int dnum;            /* BYU */
  346. char    myname[256];            /* BYU LSC */
  347. #if 0                            /* BYU LSC - not needed */
  348. char    temp[64];
  349. #endif                            /* BYU LSC */
  350.  
  351.     if ((dnum = RGfindbyVG(vg)) < 0) return(-1);        /* BYU */
  352.     if (dnum >= MAXWIND)  return(-1);                    /* BYU */
  353.  
  354. #if 0                                                            /* BYU LSC - not needed */
  355. sprintf(temp,"RGdetach: dnum = %d, vg = %d, vs = %d, Wind = %lx",    /* BYU */
  356.     dnum,RGMwind[dnum]->vg,RGMwind[dnum]->vs,RGMwind[dnum]->wind);    /* BYU */
  357. putln(temp);
  358. #endif                                                            /* BYU LSC - not needed */
  359.  
  360.     if (RGMwind[dnum]->vs != -1) {                                     /* BYU */
  361.         if (RGMwind[dnum]->wind != (GrafPtr) 0) {                    /* BYU */
  362. #if 1
  363.             strncpy((char *) RGMwind[dnum]->name,                /* BYU LSC */
  364.                     (char *) &RGMwind[dnum]->name[1],255);        /* BYU LSC */
  365.             strncpy(myname, (char *) RGMwind[dnum]->name,256);    /* BYU LSC */
  366.             c2pstr(myname);                                        /* BYU LSC */
  367.             SetWTitle(RGMwind[dnum]->wind,myname);                /* BYU LSC */
  368. #else
  369.             strncpy((char *) RGMwind[dnum]->name,                /* BYU LSC */
  370.                     (char *) &RGMwind[dnum]->name[1],255);        /* BYU LSC */
  371.             SetWTitle(RGMwind[dnum]->wind,RGMwind[dnum]->name);    /* BYU LSC */
  372. #endif
  373.         }                            /* BYU */
  374.     }                                /* BYU */
  375.     return(0);                        /* BYU */
  376. }
  377.  
  378. int RGfindbywind
  379.   (
  380.     GrafPtr wind
  381.   )
  382. {
  383. int i = 0;
  384.  
  385.     while ((i < MAXWIND) && ((!RGMwind[i]->inuse) || (RGMwind[i]->wind != wind)))
  386.         i++;
  387.     if (i >= MAXWIND) return(-1);
  388.     return(i);
  389. }
  390.  
  391. int RGupdate
  392.   (
  393.     GrafPtr wind
  394.   )
  395. {
  396. int    i = 0,done;
  397.  
  398.     if ((i = RGfindbywind(wind)) < 0)
  399.         return(-1);
  400.  
  401.     SetPort(wind);
  402.     BeginUpdate(wind);
  403.  
  404.     VGstopred(RGMwind[i]->vg);
  405.     VGpage(RGMwind[i]->vg);
  406.     done = VGpred(RGMwind[i]->vg,RGMwind[i]->vg);
  407.     EndUpdate(wind);
  408.     if (!done)
  409.         netputevent(1,128,RGMwind[i]->vg);
  410.     return(done);
  411. }
  412.  
  413. int RGsupdate
  414.   (
  415.     int i
  416.   )
  417. {
  418. int rg;
  419.  
  420.     rg = RGfindbyVG(i);
  421.  
  422.     if (rg < 0) return(0);
  423.     SetPort(RGMwind[rg]->wind);
  424.     if (!VGpred(RGMwind[rg]->vg,RGMwind[rg]->vg))
  425.     {
  426.         netputevent(1,128,i);
  427.     }
  428.     else
  429.         return(1);
  430.     return(0);
  431. }
  432.  
  433. int RGgetVG
  434.   (
  435.     GrafPtr wind
  436.   )
  437. {
  438. int i;
  439.  
  440.     i = RGfindbywind(wind);
  441.  
  442.     return(RGMwind[i]->vg);
  443. }
  444.  
  445. int RGgetdnum
  446.   (
  447.     GrafPtr wind
  448.   )
  449. {
  450.     return(RGfindbywind(wind));
  451. }
  452.  
  453. int RGgetVS
  454.   (
  455.     int dnum
  456.   )
  457. {
  458.     return(RGMwind[dnum]->vs);
  459. }
  460.  
  461. inSplash(p1, p2)
  462. Point *p1,*p2;
  463. {
  464.     if ((p1->h - p2->h > 3) || (p2->h - p1->h > 3))
  465.         return(0);
  466.     if ((p1->v - p2->v > 3) || (p2->v - p1->v > 3))
  467.         return(0);
  468.  
  469.     return(1);
  470. }
  471.  
  472. #if 0                            /* BYU LSC */
  473. long *Ticks = (long *) 0x16a;
  474. #endif
  475.  
  476. void VidSync
  477.   (
  478.     void
  479.   )
  480. {
  481. long    a;
  482. #if 1                            /* BYU LSC */
  483.     a = TickCount();            /* BYU LSC */
  484.     while (a == TickCount());    /* BYU LSC */
  485. #else                            /* BYU LSC */
  486.     a = *Ticks;
  487.     while (a == *Ticks);
  488. #endif                            /* BYU LSC */
  489. }
  490.  
  491. void RGmousedown
  492.   (
  493.     GrafPtr wind,
  494.     Point *wherein
  495.   )
  496. {
  497. long    lx,ly;
  498. char    thispaceforent[6];
  499. int        i;
  500. Point    where;
  501. char    dum[32];
  502.  
  503.     where = *wherein;
  504.     if ((i = RGfindbywind(wind)) < 0)
  505.         return;
  506.  
  507.     if (!RGMwind[i]->ingin)
  508.     {
  509.     Point    anchor,current,last;
  510. #if 0                            /* BYU LSC - was "#ifndef MPW" */
  511.     long    TickCount();
  512. #endif MPW
  513.     long    tc;
  514.     int        x0,y0,x1,y1;
  515.     Rect    rect;
  516.     
  517.         SetPort(wind);
  518.     
  519.         last  = where;
  520.         current = where;
  521.         anchor = where;
  522.     
  523.         PenPat(qd.gray);    
  524.         PenMode(patXor);
  525.     
  526.         SetRect(&rect,0,0,0,0);
  527.     
  528.         while (StillDown())
  529.         {
  530.             GetMouse(¤t);
  531.             if (inSplash(¤t,&anchor)) continue;
  532.             tc = TickCount();
  533.             while(TickCount() == tc);
  534.             VidSync();
  535.             FrameRect(&rect);
  536.     
  537.             if (anchor.v < current.v)
  538.             {
  539.                 rect.top = anchor.v;
  540.                 rect.bottom = current.v;
  541.             }
  542.             else
  543.             {
  544.                 rect.top = current.v;
  545.                 rect.bottom = anchor.v;
  546.             }
  547.     
  548.             if (anchor.h < current.h)
  549.             {
  550.                 rect.left = anchor.h;
  551.                 rect.right = current.h;
  552.             }
  553.             else
  554.             {
  555.                 rect.right = anchor.h;
  556.                 rect.left = current.h;
  557.             }
  558.     
  559.             FrameRect(&rect);
  560.             last = current;
  561.         }
  562.     
  563.         FrameRect(&rect);
  564.  
  565.         PenPat(qd.black);    
  566.         PenMode(patCopy);
  567.  
  568.         if (!inSplash(&anchor,¤t))
  569.         {
  570.             x0 = (int) ((long) rect.left * RGMwind[i]->xscale / RGMwind[i]->width );
  571.             y0 = (int) (RGMwind[i]->yscale -
  572.                     (long) rect.top * RGMwind[i]->yscale / RGMwind[i]->height);
  573.             x1 = (int) ((long) rect.right * RGMwind[i]->xscale / RGMwind[i]->width);
  574.             y1 = (int) (RGMwind[i]->yscale -
  575.                     (long) rect.bottom * RGMwind[i]->yscale / RGMwind[i]->height);
  576.             x1 = (x1 < x0+2) ? x0 + 4 : x1;
  577.             y0 = (y0 < y1+2) ? y1 + 4 : y0;
  578.  
  579.             VGzoom( i,
  580.                     x0 + RGMwind[i]->xorigin,
  581.                     y1 + RGMwind[i]->yorigin,
  582.                     x1 + RGMwind[i]->xorigin,
  583.                     y0 + RGMwind[i]->yorigin);
  584.  
  585.             VGpage(RGMwind[i]->vg);
  586.  
  587.             RGMwind[i]->xscale  = x1 - x0;
  588.             RGMwind[i]->yscale  = y0 - y1;
  589.             RGMwind[i]->xorigin = x0 + RGMwind[i]->xorigin;
  590.             RGMwind[i]->yorigin = y1 + RGMwind[i]->yorigin;
  591.  
  592.             while(!VGpred(RGMwind[i]->vg,RGMwind[i]->vg))
  593.                 Stask();
  594.             RGMlastclick = 0L;
  595.         }
  596.         else
  597.         {
  598.             if (RGMlastclick && ((RGMlastclick + GetDblTime()) > TickCount()))
  599.             {
  600.                 RGMwind[i]->xscale  = WINXMAX;    /* BYU LSC - need the "W" here */
  601.                 RGMwind[i]->yscale  = WINYMAX;    /* BYU LSC - need the "W" here */
  602.                 RGMwind[i]->xorigin = 0;
  603.                 RGMwind[i]->yorigin = 0;
  604.  
  605.                 VGzoom(i,0,0,WINXMAX-1,WINYMAX-1);    /* BYU LSC - need the "W" here */
  606.                 VGpage( RGMwind[i]->vg);
  607.                 while(!VGpred(RGMwind[i]->vg,RGMwind[i]->vg))
  608.                     Stask();
  609.                 RGMlastclick = 0L;
  610.             }
  611.             else RGMlastclick = TickCount();
  612.         }
  613.         return;
  614.     
  615.     }
  616.  
  617.     lx = (RGMwind[i]->xscale * where.h) / ((long) RGMwind[i]->width);
  618.     ly = RGMwind[i]->yscale -
  619.         ((RGMwind[i]->yscale * where.v) / ((long) RGMwind[i]->height));
  620.  
  621.     VGgindata(RGMwind[i]->vg,(int) lx,(int) ly,' ',thispaceforent);
  622.  
  623. #if 0                                                    /* BYU LSC - not needed */
  624. sprintf(dum,"GIN i: %d, vs: %d\015",i,RGMwind[i]->vs);    /* BYU 2.4.18 - changed \n to \015 */
  625. putln(dum);
  626. #endif                                                    /* BYU LSC - not needed */
  627.  
  628.     RSsendstring(RGMwind[i]->vs,thispaceforent,5);
  629.     sprintf(dum," \r\n");
  630.     RSsendstring(RGMwind[i]->vs,dum,3);
  631.     
  632.  
  633.     /*    RGMwind[i]->ingin = 0; */
  634.     unsetgraphcurs();
  635.     RGMlastclick = TickCount();
  636. }
  637.